package view;

import java.awt.Color;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
/**
 * this class is Graphic user interface of update employee details for Human Resources Employee which extends AbstractGUI
 * @author Gili
 *
 */
public class HRUpEmpDetGui extends AbstractGUI {
	
	private JTextField employeeNumberTxt;
	private JTextField firstNameTxt;
	private JTextField employeeIdTxt;
	private JTextField lastNameTxt;
	private JTextField passwordTxt;
	
	private JLabel lblLastName;
	private JLabel lblEmployeeNumber;
	private JLabel lblFirstName;
	private JLabel lblPosition;
	private JLabel warningMes = null;
	private JLabel lblEmployeeId;
	private JLabel lblPassword;
	
	private JButton btnDrawData;
	private JButton btnOk;
	private JButton btnCancel;
	
	private JComboBox<String> positionComboBox;
	
	
	public HRUpEmpDetGui() {
		
		getContentPane().setLayout(null);
		getContentPane().setBackground(Color.pink);
		lblEmployeeNumber = new JLabel("Employee Number");
		lblEmployeeNumber.setBounds(30, 33, 121, 21);
		getContentPane().add(lblEmployeeNumber);
		
		employeeNumberTxt = new JTextField();
		employeeNumberTxt.setBounds(161, 33, 86, 20);
		getContentPane().add(employeeNumberTxt);
		employeeNumberTxt.setColumns(10);
		
		lblEmployeeId = new JLabel("Employee Id");
		lblEmployeeId.setBounds(30, 67, 121, 14);
		getContentPane().add(lblEmployeeId);
		
		employeeIdTxt = new JTextField();
		employeeIdTxt.setBounds(161, 64, 97, 20);
		getContentPane().add(employeeIdTxt);
		employeeIdTxt.setColumns(10);
		employeeIdTxt.setEditable(false);
		
		lblLastName = new JLabel("Last Name");
		lblLastName.setBounds(30, 98, 121, 14);
		getContentPane().add(lblLastName);
		
		lastNameTxt = new JTextField();
		lastNameTxt.setBounds(161, 95, 97, 20);
		getContentPane().add(lastNameTxt);
		lastNameTxt.setColumns(10);
		lastNameTxt.setEditable(false);
		
		lblFirstName = new JLabel("First Name");
		lblFirstName.setBounds(30, 129, 121, 14);
		getContentPane().add(lblFirstName);
		
		firstNameTxt = new JTextField();
		firstNameTxt.setBounds(161, 126, 97, 20);
		getContentPane().add(firstNameTxt);
		firstNameTxt.setColumns(10);
		firstNameTxt.setEditable(false);
		
		lblPosition = new JLabel("Position");
		lblPosition.setBounds(30, 191, 107, 14);
		getContentPane().add(lblPosition);
		
		btnOk = new JButton("OK");
		btnOk.setBounds(142, 224, 89, 23);
		getContentPane().add(btnOk);
		
		btnDrawData = new JButton("draw data");
		btnDrawData.setBounds(257, 32, 127, 23);
		getContentPane().add(btnDrawData);
		
		btnCancel = new JButton("Back");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnCancel.setBounds(241, 224, 89, 23);
		getContentPane().add(btnCancel);
		
		lblPassword = new JLabel("Password");
		lblPassword.setBounds(30, 160, 121, 14);
		getContentPane().add(lblPassword);
		
		passwordTxt = new JTextField();
		passwordTxt.setBounds(161, 157, 97, 20);
		getContentPane().add(passwordTxt);
		passwordTxt.setColumns(10);
		passwordTxt.setEditable(false);
		
		positionComboBox = new JComboBox<String>();
		positionComboBox.setBounds(161, 188, 114, 20);
		getContentPane().add(positionComboBox);
		
		positionComboBox.addItem("");
		positionComboBox.addItem("Marketer");
		positionComboBox.addItem("Marketing Manager");
		positionComboBox.addItem("Salesman");
		positionComboBox.addItem("Customer Relations");
		positionComboBox.addItem("Human Resources");
		positionComboBox.setEditable(false);
		
		this.setBounds(500,200, 400, 300);
		//this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
	}

	public JComboBox<String> getPositionComboBox() {
		return positionComboBox;
	}

	public JTextField getEmployeeNumberTxt() {
		return employeeNumberTxt;
	}

	public JTextField getEmployeeIdTxt() {
		return employeeIdTxt;
	}

	public JTextField getLastNameTxt() {
		return lastNameTxt;
	}

	public JTextField getFirstNameTxt() {
		return firstNameTxt;
	}
	
	public JTextField getPasswordTxt() {
		// TODO Auto-generated method stub
		return passwordTxt;
	}
	
	public JLabel getWarningMes() {
		if(warningMes == null){
			warningMes = new JLabel("Employee number does not exist");
			warningMes.setForeground(Color.RED);
			warningMes.setBounds(30, 11, 339, 14);
			getContentPane().add(warningMes);
			warningMes.setVisible(false);
		}	
		return warningMes;
	}
	
	public JLabel getWarningMes(String msg) {
		if(warningMes == null){
			warningMes = new JLabel(msg);
			warningMes.setForeground(Color.RED);
			warningMes.setBounds(30, 11, 339, 14);
			//getContentPane().add(btnOk);
			warningMes.setVisible(false);
		}	
		else{
			warningMes.setText(msg);
			warningMes.setForeground(Color.RED);
			warningMes.setBounds(30, 11, 339, 14);
			//getContentPane().add(btnOk);
			warningMes.setVisible(false);
		}
		return warningMes;
	}

	public void setWarningMes() {
		getWarningMes().setVisible(true);
	}
	public void setWarningMesFalse(){
		getWarningMes().setVisible(false);
	}

	public void setWarningMes(JLabel warningMes) {
		this.warningMes = warningMes;
	}
	

	public JButton getBtnDrawData() {
		return btnDrawData;
	}

	public JButton getBtnOk() {
		return btnOk;
	}

	public JButton getBtnCancel() {
		return btnCancel;
	}
	
	public void addDrawDataActionListener(ActionListener listener){
		btnDrawData.addActionListener(listener);
	}
	
	public void addOkActionListener(ActionListener listener){
		btnOk.addActionListener(listener);
	}
	
	public void addCancelActionListener(ActionListener listener){
		btnCancel.addActionListener(listener);
	}

	public void setWarningMes(String msg) {
		// TODO Auto-generated method stub
		getWarningMes(msg).setVisible(true);
	}
	
	public void ClearText(){
		employeeNumberTxt.setText("");
		firstNameTxt.setText("");
		employeeIdTxt.setText("");
		lastNameTxt.setText("");
		passwordTxt.setText("");
		positionComboBox.setSelectedIndex(0);
	}
}
